package com.sse.product.model.rbac;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.sse.product.common.ResultCode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @ClassName ResponseVo
 * @Description TODO
 * @Author junyongli
 * @Date 2022/6/29 8:50
 * @Version 1.0
 **/

@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({"code","msg","data"})
public class ResponseVo<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private String code;
    private String msg;

    private T data;

    public ResponseVo(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static <T> ResponseVo<T> assemble(String code, String msg){
        return new ResponseVo(code, msg);
    }
    public static <T> ResponseVo<T> assemble(ResultCode result){
        return new ResponseVo(result.getCode(), result.getMsg());
    }

    public static <T> ResponseVo<T> assemble(String code, String msg, T data){
        return new ResponseVo(code, msg, data);
    }

    public static <T> ResponseVo<T> assemble(ResultCode result, T data){
        return new ResponseVo(result.getCode(), result.getMsg(), data);
    }
}
